{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3d3cd231",
   "metadata": {},
   "source": [
    "## week08\n",
    "## list练习和字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a87b4d45",
   "metadata": {},
   "source": [
    "### 上周回顾\n",
    "\n",
    ">* list列表一般方法/函数 的所有的使用场景及案例,方法如：\n",
    ">>1.append()\n",
    ">>2.pop(index)\\remove(values)\n",
    ">>3.count()\n",
    ">>4.index()\n",
    ">>5.extend()\n",
    ">>6.sort()\n",
    ">>......\n",
    ">*list高级方法 如：\n",
    ">>1.copy() 复制 不等于 赋值,复制可 等价于 切片[:]\n",
    ">>2.enu\n",
    ">*课本练习（课堂上）Don't panic==> on tap， 其中知识点：\n",
    ">>1.list的一些方法实现\n",
    ">>2.list的切片实现\n",
    ">>3.str => list 的方法 list(str)\n",
    ">>4.list =>的方法 ‘’.joint(list)\n",
    "\n",
    "### 本周内容\n",
    "### 先来做一些简单的练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03b85cb7",
   "metadata": {},
   "source": [
    "### 1.vowels2.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a826bd4",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']# 这是元音(list)\n",
    "word = \"milliways\" #这是文本(str)\n",
    "# 需求：word里出现的vowels打印出来\n",
    "for letter in word: # letteer可以随便命名，不会影响我们的结果 一版情况下，item（内容）=>简写：\n",
    "    #(循环便利的第一个位置的元素注意名字不要和已经定义过的变量重复，\n",
    "    #for循环的第二个元素决定了我们循环的内容，循环的列表，\n",
    "    #每个1元素单独在一行打印\n",
    "    #作对象 for循环 先操作word)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ba79e4b",
   "metadata": {},
   "source": [
    "# append()经常用于新建列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bad39644",
   "metadata": {},
   "outputs": [],
   "source": [
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d399eb9b",
   "metadata": {},
   "source": [
    "# 数据结构自我练习1：购物车程序项目"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13dd5359",
   "metadata": {},
   "source": [
    "# sorry老师尝试了好久不知道哪里出了问题运行不了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e0cd844",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = 'zengqiaoyi'              \n",
    "password = 123456               \n",
    "user_name = input('请输入用户名：')    \n",
    "pa_wd = int(input('请输入密码：'))     \n",
    "for i in range(1):              \n",
    "    if user_name == name and pa_wd == password:   \n",
    "        print('欢迎进入购物网购物！商品如下：')\n",
    "    else:                                         \n",
    "        print('用户名密码错误！程序退出！')\n",
    "        break\n",
    "    balance = 10000                               \n",
    "    goods_list = [\"python课本——60元\",\"华为手机——8000元\",\"小米手环——199元\",\"蜜雪冰城奶茶——8元\"]   \n",
    "    print('商品个数：',len(goods_list))               \n",
    "    shopping_car = []                             \n",
    "    for j, n in enumerate(goods_list, 1):             \n",
    "        print(j, ':', n)\n",
    "    goods_num = input('请选择商品编号:')         \n",
    "    while 0 < int(goods_num) < len(goods_list) + 1:    \n",
    "        choice_goods = goods[int(goods_num) - 1]  \n",
    "        print(choice_goods)\n",
    "        balance = balance - choice_goods[1]       \n",
    "        if balance<0:                            \n",
    "            break                                \n",
    "        print('余额', balance)\n",
    "        shopping_car.append(choice_goods_list)        \n",
    "        print('已经选择的商品：', shopping_car)\n",
    "        goods_num = input('请选择商品编号:')\n",
    "    print('余额不足')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
